/**
 * 网络请求模块封装
 */
import Vue from 'vue'
import axios from "axios"

const instance = axios.create({
    baseURL: "http://localhost:3000/api"
})

instance.interceptors.request.use( request => {
    // 读取用户登录令牌
    let adminInfo = JSON.parse(localStorage.getItem("adminInfo")|| '{}')
    // 设置请求头
    request.headers = {"authorization": adminInfo.token}
    return request  
})

instance.interceptors.response.use( response => {
    return response.data
})

Vue.prototype.$http = instance

export default instance